package com.ct.service.entity;

import java.util.Date;
import java.util.List;

import com.ct.entity.po.Approval;
import com.ct.entity.query.ApprovalQuery;
import com.ct.entity.vo.ApprovalStatusVO;
import com.ct.mappers.ReportMapper;

/**
 * @Description:
 * @Author: cby
 * @Date: 2025/5/23 17:56
 */
public class PieDataStrategy implements ReportDataStrategy<ApprovalStatusVO> {
    private ReportMapper<Approval, ApprovalQuery> reportApprovalMapper;

    public PieDataStrategy(ReportMapper<Approval, ApprovalQuery> reportApprovalMapper) {
        this.reportApprovalMapper = reportApprovalMapper;
    }

    @Override
    public ApprovalStatusVO getData(Date startDate, Date endDate) {
        ApprovalStatusVO approvalStatusVO = new ApprovalStatusVO();
        List<Approval> approvalList = reportApprovalMapper.selectApprovalByDate(startDate, endDate);

        int travelApprovalPassNum = 0;
        int advanceApprovalPassNum = 0;
        int reimbursementApprovalMaPassNum = 0;
        int reimbursementApprovalFiPassNum = 0;

        for (Approval a : approvalList) {
            if (a.getTravelApproval() == 1) {
                travelApprovalPassNum++;
            }
            if (a.getAdvanceApproval() == 1) {
                advanceApprovalPassNum++;
            }
            if (a.getReimbursementApprovalMa() == 1) {
                reimbursementApprovalMaPassNum++;
            }
            if (a.getReimbursementApprovalFi() == 1) {
                reimbursementApprovalFiPassNum++;
            }
        }
        approvalStatusVO.setTravelApprovalPassNum(travelApprovalPassNum);
        approvalStatusVO.setTravelApprovalNoPassNum(approvalList.size() - travelApprovalPassNum);
        approvalStatusVO.setAdvanceApprovalPassNum(advanceApprovalPassNum);
        approvalStatusVO.setAdvanceApprovalNoPassNum(approvalList.size() - advanceApprovalPassNum);
        approvalStatusVO.setReimbursementApprovalMaPassNum(reimbursementApprovalMaPassNum);
        approvalStatusVO.setReimbursementApprovalMaNoPassNum(approvalList.size() - reimbursementApprovalMaPassNum);
        approvalStatusVO.setReimbursementApprovalFiPassNum(reimbursementApprovalFiPassNum);
        approvalStatusVO.setReimbursementApprovalFiNoPassNum(approvalList.size() - reimbursementApprovalFiPassNum);

        return approvalStatusVO;
    }
}
